#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.configuration;


import ${package}.support.Constant;
import com.zaxxer.hikari.HikariDataSource;
import tk.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 公共配置
 *
 * @author chenjianbo
 */
@Configuration
@MapperScan("${package}.dao.ibatis")
@EnableJpaRepositories(value = {"${package}.dao.jpa"}, transactionManagerRef = Constant.JPA_TRANSACTION)
public class DefaultAutoConfiguration implements WebMvcConfigurer {

    @Resource
    private HikariDataSource dataSource;

    /**
     * JPA事务管理器
     */
    @Bean(Constant.JPA_TRANSACTION)
    public JpaTransactionManager jpaTransactionManager() {
        JpaTransactionManager jpa = new JpaTransactionManager();
        jpa.setDataSource(dataSource);
        jpa.setRollbackOnCommitFailure(true);
        return jpa;
    }

}
